using System;
using System.Data;
using PCSComUtils.PCSExc;
using PCSComProduction.WorkOrder.DS;
using PCSComProduct.Items.DS;



namespace PCSComProduction.WorkOrder.BO
{
	public class WORoutingBO //:  IWORoutingBO
	{
		public WORoutingBO()
		{
			//
			// TODO: Add constructor logic here
			//
		}
		public DataRow GetWORoutingMaster(int pintWODetailID)
		{
			return null;
		}

		public DataTable GetWORoutingDetail(int pintWODetailID)
		{
			return null;
		}
		/// <summary>
		/// Update Master table(WorkOrderDetail) and detail table(WORouting)
		/// </summary>
		/// <param name="pobjMaster"></param>
		/// <param name="pdtbDetail"></param>
		public void UpdateWORouting(object pobjMaster, DataTable pdtbDetail)
		{
			
		}
		public void SaveWORouting(object pobjMaster, DataTable pdtbDetail)
		{}

		/// <summary>
		/// This method is used to delete all the routing information
		/// of a specific Work Order Detail ID
		/// and then update the Increment, routing description of 
		/// this work order detail
		/// </summary>
		/// <param name="pintWODetailID"></param>
		//[AutoComplete(true)]
		public void DeleteWORouting(int pintWODetailID)
		{
			try
			{
				//first we need to delete all the routing information
				PRO_WORoutingDS dsPRO_WORoutingDS = new PRO_WORoutingDS();
				dsPRO_WORoutingDS.DeleteWORoutingByWODetailID(pintWODetailID);

				//second we need to update some information back to the Work Order Line
				PRO_WorkOrderDetailDS dsPRO_WorkOrderDetailDS = new PRO_WorkOrderDetailDS();
				PRO_WorkOrderDetailVO voPRO_WorkOrderDetailVO = new PRO_WorkOrderDetailVO();
				voPRO_WorkOrderDetailVO.Increment = 0;
				voPRO_WorkOrderDetailVO.WorkOrderDetailID = pintWODetailID;
				voPRO_WorkOrderDetailVO.Description = String.Empty;
				dsPRO_WorkOrderDetailDS.UpdateWORouting(voPRO_WorkOrderDetailVO);

			}			
			catch (PCSDBException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw new Exception(ex.Message, ex);
			}

		}


		/// <summary>
		/// Get some basic information of the Product
		/// by the Work Order Detail ID
		/// </summary>
		/// <param name="pintWorkOrderDetailID"></param>
		/// <returns></returns>
		//[AutoComplete(true)]
		public object GetProductInfo(int pintWorkOrderDetailID)
		{
			try
			{
				ITM_ProductDS dsITM_ProductDS = new ITM_ProductDS();
				return dsITM_ProductDS.GetProductInfoByWorkOrderDetailID(pintWorkOrderDetailID);
			}
			catch (PCSDBException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw new Exception(ex.Message, ex);
			}
		}

		/// <summary>
		/// Get the increment and routing description
		/// </summary>
		/// <param name="pintWorkOrderDetailID"></param>
		/// <returns></returns>
		//[AutoComplete(true)]
		public object GetWorkOrderDetailInfo(int pintWorkOrderDetailID)
		{
			try
			{
				PRO_WorkOrderDetailDS dsPRO_WorkOrderDetailDS = new PRO_WorkOrderDetailDS();
				
				return dsPRO_WorkOrderDetailDS.GetWorkOrderDetailInfo(pintWorkOrderDetailID);
			}
			catch (PCSDBException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw new Exception(ex.Message, ex);
			}
		}

		/// <summary>
		/// This method is used to get all the routing information
		/// </summary>
		/// <param name="pintWorkOrderDetailID"></param>
		/// <returns></returns>
		//[AutoComplete(true)]
		public DataSet GetWORouting(int pintWorkOrderDetailID)
		{
			try
			{
				PRO_WORoutingDS dsPRO_WORoutingDS = new PRO_WORoutingDS();
				return dsPRO_WORoutingDS.GetWORoutingByWODetailID(pintWorkOrderDetailID);
			}
			catch (PCSDBException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw new Exception(ex.Message, ex);
			}
		}

		/// <summary>
		/// This method is used to get some basic information from the work order master
		/// </summary>
		/// <param name="pintWorkOrderDetailID"></param>
		/// <returns></returns>
		//[AutoComplete(true)]
		public object GetWorkOrderMasterInfo(int pintWorkOrderDetailID)
		{
			try
			{
				
				PRO_WorkOrderMasterDS dsPRO_WorkOrderMasterDS = new PRO_WorkOrderMasterDS();
				return dsPRO_WorkOrderMasterDS.GetWOMasterInfoByWODetailID(pintWorkOrderDetailID);
			}
			catch (PCSDBException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw new Exception(ex.Message, ex);
			}
		}

		/// <summary>
		/// This method is used to update information back to database
		/// we need to update two tables
		/// 1.Table Work Order Detail (Increment and Description)
		/// 2.Table WORouting (all information)
		/// </summary>
		/// <param name="pobjWorkOrderDetailVO"></param>
		/// <param name="pdstWORoutingData"></param>
		//[AutoComplete(true)]
		public void SaveWORouting(object pobjWorkOrderDetailVO, DataSet pdstWORoutingData)
		{
			try
			{
				//first we need to update the information back to the Work Order Detail
				PRO_WorkOrderDetailDS dsPRO_WorkOrderDetailDS = new PRO_WorkOrderDetailDS();
				dsPRO_WorkOrderDetailDS.UpdateWORouting(pobjWorkOrderDetailVO);

				//second we need to update the information of the wrouting itself
				PRO_WORoutingDS dsPRO_WORoutingDS = new PRO_WORoutingDS();
				dsPRO_WORoutingDS.UpdateDataSet(pdstWORoutingData);
			}
			catch (PCSDBException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw new Exception(ex.Message, ex);
			}
		}
		#region IObjectBO Members

		//**************************************************************************              
		///    <Description>
		///       This method uses to 
		///    </Description>
		///    <Inputs>
		///            
		///    </Inputs>
		///    <Outputs>
		///       
		///    </Outputs>
		///    <Returns>
		///       
		///    </Returns>
		///    <Authors>
		///       CanhNv
		///    </Authors>
		///    <History>
		///       04/09/2007
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public void UpdateDataSet(DataSet dstData)
		{
			PRO_WORoutingDS  dsWORouting = new PRO_WORoutingDS();
			dsWORouting.UpdateDataSet(dstData);
		}

		public void Update(object pObjectDetail)
		{
			// TODO:  Add WORoutingBO.Update implementation
		}

		public void Delete(object pObjectVO)
		{
			// TODO:  Add WORoutingBO.Delete implementation
		}

		public void Add(object pObjectDetail)
		{
			// TODO:  Add WORoutingBO.Add implementation
		}

		public object GetObjectVO(int pintID, string VOclass)
		{
			// TODO:  Add WORoutingBO.GetObjectVO implementation
			return null;
		}

		#endregion

		//[AutoComplete(true)]
		public DataSet ListWORoutingByProduct(int pintProductID, int pintworkOrderDetailId)
		{
			PRO_WORoutingDS dsWORouting = new PRO_WORoutingDS();
			return dsWORouting.ListWORoutingByProduct(pintProductID,pintworkOrderDetailId);
		}
		
		//[AutoComplete(true)]
		public void UpdateProductionLine(int pintProductionLineID, int pintWODetailID)
		{
			PRO_WORoutingDS dsRouting = new PRO_WORoutingDS();
			dsRouting.UpdateProductionLine(pintProductionLineID, pintWODetailID);
		}
	}
}
